﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Data;
using T.ServiceComponent.DataAccessEx.Core;

namespace T.FAS.Runtime.Base.Dao
{
    /// <summary>
    /// SQL帮助类
    /// </summary>
    public static class SQLTool
    {
        public static string GetInIDs(List<string> ids)
        {
            return "'" + string.Join("','", ids) + "'";
        }

        public static string GetInIDSQLs(List<string> ids, ITDatabase db, out List<IDbDataParameter> param)
        {
            param = null;
            var tmp = new List<IDbDataParameter>();
            if (ids == null || ids.Count == 0 || db == null) return null;
            int i = 0;
            string sql = string.Empty;
            ids.ForEach(x =>
            {
                string parName = $"@par{i++}";
                sql += parName + ",";
                tmp.Add(db.MakeInParam(parName, x));
            });
            param = tmp;
            return sql.TrimEnd(',');
        }
    }
}
